package com.hzit.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.GoodsDesc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.hzit.manager.service.IGoodsDescService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品描述Controller
 * 
 * @author hbxfwf
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/desc")
public class GoodsDescController extends BaseController
{
    @Autowired
    private IGoodsDescService goodsDescService;

    /**
     * 查询商品描述列表
     */
        @GetMapping("/list")
    public TableDataInfo list(GoodsDesc goodsDesc)
    {
        startPage();
        List<GoodsDesc> list = goodsDescService.selectGoodsDescList(goodsDesc);
        return getDataTable(list);
    }

    /**
     * 导出商品描述列表
     */
        @Log(title = "商品描述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsDesc goodsDesc)
    {
        List<GoodsDesc> list = goodsDescService.selectGoodsDescList(goodsDesc);
        ExcelUtil<GoodsDesc> util = new ExcelUtil<GoodsDesc>(GoodsDesc.class);
        util.exportExcel(response, list, "商品描述数据");
    }

    /**
     * 获取商品描述详细信息
     */
        @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(goodsDescService.selectGoodsDescByGoodsId(goodsId));
    }
    @GetMapping(value = "/findGoodsDescById/{goodsId}")
    public R<GoodsDesc> findGoodsDescById(@PathVariable("goodsId") Long goodsId)
    {
        return R.ok(goodsDescService.selectGoodsDescByGoodsId(goodsId));
    }
    /**
     * 新增商品描述
     */
        @Log(title = "商品描述", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsDesc goodsDesc)
    {
        return toAjax(goodsDescService.insertGoodsDesc(goodsDesc));
    }

    /**
     * 修改商品描述
     */
        @Log(title = "商品描述", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsDesc goodsDesc)
    {
        return toAjax(goodsDescService.updateGoodsDesc(goodsDesc));
    }

    /**
     * 删除商品描述
     */
        @Log(title = "商品描述", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(goodsDescService.deleteGoodsDescByGoodsIds(goodsIds));
    }
}
